/**
 * Created with IntelliJ IDEA.
 * Description:线程中断 手动设置标志位
 * User: lenovo
 * Date: 2022-09-05
 * Time: 22:20
 */
public class Demo9 {
    //多个线程都是共用同一块内存空间,isQuit每个线程都能使用
    public static boolean isQuit = false;
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(()->{
            while(!isQuit){
                System.out.println("hello thred");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t线程执行完了");


        },"这是俺的线程");

        t.start();
        Thread.sleep(5000);
        isQuit = true;
        System.out.println("设置t线程结束");
    }
}
